package alkaid.eis.schedule.domain;

import java.util.Set;

import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Root;

import org.springframework.data.jpa.domain.Specification;

import alkaid.eis.schedule.domain.JobLog.Level;
import lombok.experimental.UtilityClass;

/**
 * 任务日志查询条件
 *  
 * @author Lucky Yang
 * @since 0.0.1
 */
@UtilityClass
public class JobLogSpecifications {
    public Specification<JobLog> empty() {
        return (Root<JobLog> root, CriteriaQuery<?> query, CriteriaBuilder cb) -> {
            return null;
        };
    }

    public Specification<JobLog> levelIn(Set<Level> levels) {
        return (Root<JobLog> root, CriteriaQuery<?> query, CriteriaBuilder cb) -> {
            return cb.in(root.get("level")).value(levels);
        };
    }

    public Specification<JobLog> jobInfoEqual(JobInfo jobInfo) {
        return (Root<JobLog> root, CriteriaQuery<?> query, CriteriaBuilder cb) -> {
            return cb.equal(root.get("jobInfo"), jobInfo);
        };
    }
}